<?php

namespace app\admin\controller;

use app\admin\model\SystemNode as SystemNodeModel;

class Menu extends CheckLogin
{

    public function index(){
        $node = new SystemNodeModel();
        $nodes = $node->getNodes();
        $this->assign(['nodes'=>$nodes]);
        return $this->fetch();
    }


    public function add()
    {
        if ($this->request->isPost()) {
            $data = $this->request->post();
            $node = new SystemNodeModel();
            if ($node->add($data)) {
                return $this->jsonSuccess('添加成功...', ['url' => '/menu/index']);
            }
        }
        return $this->jsonFail('添加失败');
    }

    public function edit()
    {
        if ($this->request->isPost()) {
            $data = $this->request->post();
            $node = new SystemNodeModel();
            if ($node->edit($data)) {
                return $this->jsonSuccess('修改成功...', ['url' => '/menu/index']);
            }
        }
        return $this->jsonFail('修改失败');
    }

    public function del(){
        $nodeId = $this->request->post('id');
        $node = new SystemNodeModel();
        if ($node->del($nodeId)) {
            return $this->jsonSuccess('删除成功');
        }
        return $this->jsonFail('删除失败');
    }


}
